<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-11-10 10:34:52
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-11-11 10:48:24
 * @Description: 
 * 
-->
<template>
  <el-dialog
    :title="titleMap[mode]"
    v-model="visible"
    :width="580"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="dialogForm"
      label-width="100px"
      label-position="right"
    >
      <sk-tabs type="border-card">
        <el-tab-pane ref="tab" label="班次信息">
          <el-form-item label="岗位名称" prop="name">
            <el-input v-model="form.name" clearable />
          </el-form-item>
          <el-form-item label="岗位职责">
            <el-input v-model="form.responsibilities" clearable />
          </el-form-item>
          <el-form-item label="岗位流程">
            <el-input v-model="form.process" clearable />
          </el-form-item>
          <el-form-item label="岗位级别">
            <el-input v-model="form.level" clearable />
          </el-form-item>
          <el-alert type="info" show-icon :closable="false">
            <p>
              <b>班组岗位：</b>同岗位，同班次任意人
              刷卡/自主报工，都属于当前班次、岗位的员工的产量，遇到请假等原因的，需要手工删除
            </p>
            <p><b>个人计件：</b>刷卡/报工产量属于个人</p>
          </el-alert>
          <el-form-item label="产量计算">
            <skDicRadioBox
              v-model="form.productivity_method_id"
              :code="'Productivity_Method'"
            ></skDicRadioBox>
          </el-form-item>
          <el-alert type="info" show-icon :closable="false">
            <p>
              <b>刷卡报工</b> 数据来源于生产中心的过数记录，<b>自主提交</b>
              不参考系统数据，员工自己报工
            </p>
          </el-alert>
          <el-form-item label="报工方式">
            <skDicRadioBox
              v-model="form.productivity_way_id"
              :code="'Productivity_Way'"
            ></skDicRadioBox>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" clearable />
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane ref="tab" label="人员信息">
          <sc-VxeTable
            ref="xGrid1"
            :data="form.users"
            :tablecode="'comprehensive_shift_user'"
            :sortable="true"
          >
          </sc-VxeTable>
        </el-tab-pane>
      </sk-tabs>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
import skDicRadioBox from "@/components/skDicRadioBox";
export default {
  emits: ["success", "closed"],
  components: { skDicSelect, skAutoChoose, skDicRadioBox },
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增",
        edit: "编辑",
      },
      visible: false,
      isSaveing: false,
      //表单数据
      form: {
        users: [],
        productivity_method_id: -1,
        productivity_way_id: 1,
      },
      //验证规则
      rules: {
        name: [{ required: true, message: "请输入班次名" }],
      },
      //所需数据选项
    };
  },
  watch: {},
  mounted() {},
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          this.isSaveing = true;
          this.$API.comprehensive.position.save
            .post(this.form)
            .then(res => {
              if (res.code == 200) {
                this.$emit("success", this.form, this.mode);
                this.visible = false;
                this.$message.success("操作成功");
              }
            })
            .finally(() => {
              this.isSaveing = false;
            });
        }
      });
    },
    getInfo(id) {
      this.$API.comprehensive.position.info
        .get({
          filter: [{ id: id }],
        })
        .then(res => {
          if (res.code == 200) {
            this.form = res.data;
          }
        })
        .finally(() => {
          this.digloading = false;
        });
    },
    //表单注入数据
    setData(data) {
      this.getInfo(data);
    },
  },
};
</script>

<style scoped></style>
